package hu.bme.mit.Nonogram.client;

import com.google.gwt.user.client.ui.Label;

public class NonogramTableElement extends Label {
	enum State {BLANK, MARKED, INVALID} 
	
	private State state;
	private boolean solve;
	private int coordX;
	private int coordY;
	
	public NonogramTableElement(int x, int y, boolean solve_state) {
		super();
		setWidth("25px");
		setHeight("25px");
		setState(State.BLANK);
		setStyleName("blank"); 
		coordX = x;
		coordY = y;
		solve = solve_state;
		super.setVisible(true);
	}

	public State getState() {
		return state;
	}

	public void setState(State state) {
		this.state = state;
	}
	
	public void changeStateBack () {
		switch (state) {
		case BLANK: 	setState(State.INVALID); 
						setStyleName("invalid"); 
						break;
		case MARKED: 	
						setState(State.BLANK);
						setStyleName("blank"); 
						break;
						
		case INVALID: 	setState(State.MARKED); 
						setStyleName("marked"); 
						break;

		default:
			break;
		}
	}
	public void changeState() {
		switch (state) {
		case BLANK: 	setState(State.MARKED); 
						setStyleName("marked"); 
						break;
		case MARKED: 	if (solve) {
							setState(State.INVALID);
							setStyleName("invalid"); 
							break;
						}
						else {
							setState(State.BLANK); 
							setStyleName("blank"); 
							break;
						}
		case INVALID: 	setState(State.BLANK); 
						setStyleName("blank"); 
						break;

		default:
			break;
		}
	}

	public int getCoordX() {
		return coordX;
	}

	public int getCoordY() {
		return coordY;
	}
	
	public boolean getSolve () {
		return solve;
	}

}
